package c.e.b.h.e.p;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;

/* compiled from: ClsFileOutputStream */
public class b extends FileOutputStream {
    public static final FilenameFilter d = new a();
    public final String a;
    public File b;
    public boolean c = false;

    /* compiled from: ClsFileOutputStream */
    public class a implements FilenameFilter {
        public boolean accept(File file, String str) {
            return str.endsWith(".cls_temp");
        }
    }

    public b(File file, String str) throws FileNotFoundException {
        String str2 = ".cls_temp";
        super(new File(file, c.b.a.a.a.D(str, str2)));
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(file);
        String d = c.b.a.a.a.d(stringBuilder, File.separator, str);
        this.a = d;
        this.b = new File(c.b.a.a.a.D(d, str2));
    }

    public synchronized void close() throws IOException {
        if (!this.c) {
            this.c = true;
            flush();
            super.close();
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(this.a);
            stringBuilder.append(".cls");
            File file = new File(stringBuilder.toString());
            if (this.b.renameTo(file)) {
                this.b = null;
                return;
            }
            String str = "";
            if (file.exists()) {
                str = " (target already exists)";
            } else if (!this.b.exists()) {
                str = " (source does not exist)";
            }
            StringBuilder stringBuilder2 = new StringBuilder();
            stringBuilder2.append("Could not rename temp file: ");
            stringBuilder2.append(this.b);
            stringBuilder2.append(" -> ");
            stringBuilder2.append(file);
            stringBuilder2.append(str);
            throw new IOException(stringBuilder2.toString());
        }
    }

    public void n() throws IOException {
        if (!this.c) {
            this.c = true;
            flush();
            super.close();
        }
    }
}
